#include "SpotLightSource.h"

namespace lib3dw
{
	SpotLightSource::SpotLightSource()
	{
		direction = new GLfloat[3];
		direction[0] = 0.0;
		direction[1] = 0.0;
		direction[2] = -1.0;

		cutoff = 32.0;
		exponent = 20.0;
	}

	SpotLightSource::~SpotLightSource()
	{
		delete[] direction;
	}

	LightType SpotLightSource::GetLightType()
	{
		return SpotLight;
	}

	
	void SpotLightSource::SetDirection(GLfloat x, GLfloat y, GLfloat z)
	{
		direction[0] = x;
		direction[1] = y;
		direction[2] = z;
	}

	void SpotLightSource::SetCutoff(GLfloat cut)
	{
		cutoff = cut;
	}

	void SpotLightSource::SetExponent(GLfloat exp)
	{
		exponent = exp;
	}

	const GLfloat* SpotLightSource::GetDirection() const
	{
		return direction;
	}

	GLfloat SpotLightSource::GetCutoff()
	{
		return cutoff;
	}
	
	GLfloat SpotLightSource::GetExponent()
	{
		return exponent;
	}
	
	void SpotLightSource::SetupLightMatrices() const
	{
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		float near = position[1] <= 0.0 ? 1.0 : position[1];
		gluPerspective(30.0f, 1.0f, near, 20.0f);
		glGetFloatv(GL_MODELVIEW_MATRIX, lightProjMat);

		glLoadIdentity();
		gluLookAt(position[0], position[1], position[2],
			position[0], -2.0f, position[2],
			0.0f, 0.0f, 1.0f);
		glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMat);
		glPopMatrix();
	}
	
	int SpotLightSource::GetShadowMapSize()
	{
			//glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
			return spotLightShadowMapSize;
	}
}